package ru.vsu.cs.pm.models;

import org.apache.wicket.injection.web.InjectorHolder;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import ru.vsu.cs.pm.beans.AccountManager;

/**
 * User: ohodyakov
 * Date: 23.12.2010
 * Time: 10:51:04
 */
public class AccountModel extends LoadableDetachableModel<Account> {

    @SpringBean
    private AccountManager accountManager;

    private Integer id;

    public AccountModel() {
        InjectorHolder.getInjector().inject(this);
    }

    public AccountModel(Integer id) {
        this.id = id;
        InjectorHolder.getInjector().inject(this);
    }

    public AccountModel(Account account) {
        super(account);
        this.id = account.getId();
        InjectorHolder.getInjector().inject(this);
    }

    @Override
    protected Account load() {
        if(id == null) {
            return new Account();
        }
        return accountManager.getAccount(id);
    }
}
